Scare plugin

Discussion in 'Programming' started by Maz0, Apr 25, 2017.

Thread Status:
Not open for further replies.
  1. Hey Spigot !

    I've tried to make an Scare plugin. I've written a code, that unfortunately doesn't work. I was trying to find the answear on stacko**rflow, but no-one really helped me. I hope, that you could help me, so my code'll work.

    Sorry for any grammar mistakes, I'm not from English talking countries.

    Code (Text):
    package me.maz0.scare;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    import net.md_5.bungee.api.ChatColor;

    public class Main extends JavaPlugin implements Listener {
       
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            Bukkit.getLogger().info("Scare plugin has been enabled");
            Bukkit.getLogger().info("Scare plugin by Maz0");
        }
       
         @SuppressWarnings("null")
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
             Player p = (Player)sender;
             if (cmd.getName().equalsIgnoreCase("scare") && sender instanceof Player) {
                 if(args.length == 0) {
                     p.sendMessage(ChatColor.RED +"You must specify a command !");
                     
            Player t = Bukkit.getServer().getPlayer(args[2]);
           
            if(t == null) {
                p.sendMessage(ChatColor.RED + "Could not find a player named " + ChatColor.YELLOW +  args[2] + " !");
                 FileConfiguration config = getConfig();
                 p.sendMessage(ChatColor.RED + "Invalid arguments, try /scare help");
             if (args[1].equalsIgnoreCase("help") && sender instanceof Player) {
                 t.sendMessage("/scare help displays this help");
                 t.sendMessage("/scare signs shows signs with texts (1-3)");
                 t.sendMessage("/scare scream screms at player");
             if (args[1].equalsIgnoreCase("signs") && sender instanceof Player) {
                 Block block = t.getLocation().subtract(0, 1, 0).getBlock();
                 @SuppressWarnings("unused")
                Material type = block.getType();
                 block.setType(Material.SIGN);
                 Sign sign = (Sign) block.getState();
                 sign.setLine(0, config.getString("Sign1"));
                 Block block2 = t.getLocation().subtract(1, 0, 0).getBlock();
                @SuppressWarnings("unused")
                Material type2 = block.getType();
                 block2.setType(Material.SIGN);
                 Sign sign2 = (Sign) block.getState();
                 sign2.setLine(0, config.getString("Sign2"));
                 Block block3 = t.getLocation().subtract(1, 0, 1).getBlock();
                 @SuppressWarnings("unused")
                 Material type3 = block.getType();
                 block3.setType(Material.SIGN);
                 Sign sign3 = (Sign) block.getState();
                 sign3.setLine(0, config.getString("Sign3"));
            if (args[1].equalsIgnoreCase("scream") && sender instanceof Player) {
                t.playSound(t.getLocation(), Sound.FUSE, 2F, 1F);
                t.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 60, 1));
                            } else {
                                p.sendMessage(ChatColor.RED + "Invalid arguments, try /scare help");
                            }
                         }            
                     }    
                 }
             }
        }return true;
    }}
     
  2. 1. No precise descriptions (What are you trying to do? Why you can tell it is not working?)
    2. Misleading variable names (Player t)
    3. Messy code
    4. wat (@SuppressWarnings("unused") * N)

    That's why people didn't help you, and you cannot expect any constructive help before you understand how to ask a question.
     
  3. Okay, I won't ask anymore and I'll try to find the error myself.

    Thanks
     
Thread Status:
Not open for further replies.