Please help, I created a Smite plugin.

Discussion in 'Plugin Development' started by Miner_Saint, Aug 7, 2015.

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

    Miner_Saint

    I created a smite plugin but I got a few errors I don't know how to fix them
    PLEASE HELP ME!! ;C
    Heres the code

    Code:
    package me.miner.Smite;
    
    import java.util.logging.Logger;
    
    
    
    
    
    
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Smite extends JavaPlugin {
        public static Smite plugin;
        public final Logger logger = Logger.getLogger("Minecraft");
       
        public void onDisable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName()+ "is now disabled.");
           
           
        }
       
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName()+" version " +pdfFile.getVersion() + "is now enabled.");
           
           
        }
       
       
    
        @SuppressWarnings("deprecation")
        public boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            World world = player.getWorld();
            if(commandLabel.equalsIgnoreCase("smite")) {
                if(args.length == 0) {
                    Block targetblock = player.getTargetBlock(null, 50);
                    Location location = targetblock.getLocation();
                    world.strikeLightning(location);
                }    else if (args.length == 1) {
                    if(player.getServer().getPlayer(args[0]) !=null) {
                        Player targetplayer = player.getServer().getPlayer(args[0]);
                        Location location = targetplayer.getLocation();
                        world.strikeLightning(location);
                        player.sendMessage(ChatColor.GRAY + "Smiting player " + targetplayer.getDisplayName());
                    } else {
                        player.sendMessage(ChatColor.RED + "Error: That player is offline.");
                    }
                } else if (args.length > 1) {
                    player.sendMessage(ChatColor.RED + "Error: Too many arguments!");
                }
            }
            return false;
        }
       
    
    }


    The errors I'm getting is here http://prntscr.com/82aa1x
     
    Last edited: Aug 8, 2015
  2. Offline

    sander_blaadjes

    @Miner_Saint The errors you get are very basic, you should learn Java before making bukkit plugins.
     
  3. Offline

    SantaClawz69

    #1: if player.getServer().getPlayer(args[0]) != null) { delete the random ")" you put in there.
    #2: add your parentheses on your if statement in line 43
    #3: You have to import Location from org.bukkit.Location
    #4: You have to import Block from org.bukkit.block not import net.minecraft.server.v1_8_R2.Block;

    And finally, if you want some more exact help paste it in code text box not just plain text.

    Also learn some java, if you don't know any of these errors you're doomed.
     
    Last edited by a moderator: Aug 7, 2015
    Miner_Saint likes this.
  4. Offline

    Miner_Saint

    Wheres the code box? I'm new to these forums sorry @SantaClawz69
     
  5. @Miner_Saint [code][/code] and for java just do code=java
     
  6. Offline

    Miner_Saint

    I did it, I just can't see where I have gone wrong now, if someone can just edit my code and paste it here that would be great. please guys D: I'm a learning java so dun be mean ;c
    @SantaClawz69 and maybe anyone else please!
     
    Last edited: Aug 7, 2015
  7. Offline

    SantaClawz69

    if player.getServer().getPlayer(args[0])!=null{
    It's supposed to be if(player.getServer().getPlayer(args[0]) !=null) {

    And we're not going to spoon feed you all the code. We'll help you but we're not going to give you everything.
     
  8. Offline

    Miner_Saint

    The method getTargetBlock(HashSet<Byte>, int) is ambiguous for the type Player Only error left
    well it says theres 4 errors but thats the only one that is red. @SantaClawz69

    If this works after you tell me how to fix it, then I really appreciate your help.
     
  9. Offline

    SantaClawz69

    You're using getTargetBlock wrong. Don't use getTargetBlock if you want to get the block a player is looking at, use:
    event.getPlayer().getEyeLocation().getBlock(); instead.
     
  10. Offline

    Miner_Saint

    I did that and now it has a line through the event and its an error do I make into a variable? or what do you suggest? @SantaClawz69
     
  11. Offline

    SuperOriginal

    So telling someone to learn Java is on topic while posting helpful links to valuable resources isn't . +1 moderation

    Now they edit my posts to forge my tone. Nice.
     
    Last edited: Aug 7, 2015
  12. Offline

    Miner_Saint

    Can someone help me please ;c I really want it to work @SuperOriginal Do you know?
     
    Last edited: Aug 7, 2015
  13. Offline

    SuperOriginal

    First of all SantaClawz is incorrect, you need to use getTargetBlock to get the block a player is looking at. getEyeLocation is just the location of their head.
     
  14. Offline

    Miner_Saint

    I don't know anymore I'm so confused now :c btw I'm watching this guy
    @SuperOriginal
    what do I do to fix that bit now?

    Can anyone help me with this last bug ;c This is my error http://prntscr.com/82aa1x

    and I will edit my code in a sec. Please help me someone its just this last error! I really appreciate the help

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

    SantaClawz69

    Okay, are you trying to smite a player or the block you're looking at?

    Yeah, just realized that. My bad
     
    SuperOriginal likes this.
  16. Offline

    CraterHater

    @Miner_Saint I used this for one of my plugins:
    Code:
     @SuppressWarnings("deprecation")
    Block x = p.getTargetBlock(null, 256);
    p.getWorld().strikeLightning(x.getWorld().getHighestBlockAt(x.getLocation()).getLocation().clone().add(0.0D, 1.0D, 0.0D)).setFireTicks(0);
          
     
  17. Offline

    Miner_Saint

    For that part I'm smiting a block

    For the whole thing basically if you type /smite withought a players name it should summon lightning on the block you are looking at and secondly if you type /smite miner_saint then it should smite them and kill them. @CraterHater @SantaClawz69 @SuperOriginal

    I think its just that part that doesn't work, the smiting a block part. so I tried removing that part and it had no errors or anything then when I tried it on my server it didn't work, I typed /smite (player's name) and nothing happened. So please help!
     
  18. Offline

    CraterHater

    @Miner_Saint ok I got it to work, this is the code.
    Code:
     Player player = (Player) sender;
      World world = player.getWorld();
    if(cmd.getName().equalsIgnoreCase("smite")) {
    player.sendMessage("0");
    if(args.length == 0) {           
    player.sendMessage("1");
    Block targetblock = player.getTargetBlock(null, 256);
    Location location = targetblock.getLocation();
    world.strikeLightning(location);
    player.sendMessage("2");
    }    else if (args.length == 1) {
    if(player.getServer().getPlayer(args[0]) !=null) {
    player.sendMessage("3");
    Player targetplayer = player.getServer().getPlayer(args[0]);
    Location location = targetplayer.getLocation();
    world.strikeLightning(location);
    player.sendMessage("4");
    player.sendMessage(ChatColor.GRAY + "Smiting player " + targetplayer.getDisplayName());
    } else {
    player.sendMessage(ChatColor.RED + "Error: That player is offline.");
      }
    } else if (args.length > 1) {
    player.sendMessage(ChatColor.RED + "Error: Too many arguments!");
    I know this is kinda spoonfeeding but I think that if you study this code really well that you will learn something of it, don't just copy paste this but try actually understanding it, will you?
     
    Miner_Saint likes this.
  19. Offline

    Miner_Saint

    Thanks anyway but I got some help of my friend and he taught me a few things, he didn't spoon feed me it. He is awesome. I don't know how to mark this as "Solved" but if a staff member can that would be great thanks for the help peeps.
     
    Last edited: Aug 8, 2015
Thread Status:
Not open for further replies.

Share This Page