bukkit plugin syntax error "}",{expected

Discussion in 'Plugin Development' started by farting777, Sep 19, 2014.

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

    farting777

    on the 5th to bottom line of my code it says syntax error on token "}",{ expected.
    i think it has to do with how many { and }s there are...
    heres my code:
    package me.farting777.eztp;

    import java.util.Random;
    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Color;
    import org.bukkit.FireworkEffect;
    import org.bukkit.FireworkEffect.Type;
    import org.bukkit.Location;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Firework;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerLevelChangeEvent;
    import org.bukkit.inventory.meta.FireworkMeta;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin{
    public final Logger logger = Logger.getLogger("Minecraft");
    public static Main plugin;
    private PlayerLevelChangeEvent event;

    public void onEnable(){
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " has been enabled!");
    }

    public void onDisable(){
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " v" + pdfFile.getVersion() + " has been disabled!");
    }

    @SuppressWarnings("deprecation")
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;

    if(cmd.getName().equalsIgnoreCase("eztp")) {
    if(args.length == 0){
    player.sendMessage(ChatColor.RED + "Usage:/eztp (player) or /eztp (player) (player)");
    }else if(args.length == 1){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    Location targetPlayerLocation = targetPlayer.getLocation();
    player.teleport(targetPlayerLocation);
    player.sendMessage(ChatColor.GREEN + "teleportation complete!");
    }else if(args.length == 2){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    Player targetPlayer1 = player.getServer().getPlayer(args[1]);
    Location targetPlayer1Location = targetPlayer1.getLocation();
    targetPlayer.teleport(targetPlayer1Location);
    player.sendMessage(ChatColor.AQUA + "teleportation complete!");

    }else if(cmd.getName().equalsIgnoreCase("eztp test")){
    player.sendMessage(ChatColor.GREEN + "Hi, you tested eztp!");

    }else if(cmd.getName().equalsIgnoreCase("eztp fun2") && sender instanceof Player){
    Location location = player.getLocation();
    player.playSound(location, Sound.CAT_PURREOW, 4, 10);

    }else if(cmd.getName().equalsIgnoreCase("eztp fun3") && sender instanceof Player){
    player.sendMessage(ChatColor.MAGIC + "FFFUUNNN TTTIIIMMMEEE!!!!");

    }else if(cmd.getName().equalsIgnoreCase("eztp fun") && sender instanceof Player){
    Player p = event.getPlayer();
    if (p.hasPermission("firework.level")){

    //Spawn the Firework, get the FireworkMeta.
    Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
    FireworkMeta fwm = fw.getFireworkMeta();

    //Our random generator
    Random r = new Random();

    //Get the type
    int rt = r.nextInt(5) + 1;
    Type type = Type.BALL;
    if (rt == 1) type = Type.BALL;
    if (rt == 2) type = Type.BALL_LARGE;
    if (rt == 3) type = Type.BURST;
    if (rt == 4) type = Type.CREEPER;
    if (rt == 5) type = Type.STAR;

    //Get our random colors
    int r1i = r.nextInt(17) + 1;
    int r2i = r.nextInt(17) + 1;
    Color c1 = getColor(r1i);
    Color c2 = getColor(r2i);

    //Create our effect with this
    FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();

    //Then apply the effect to the meta
    fwm.addEffect(effect);

    //Generate some random power and set it
    int rp = r.nextInt(2) + 1;
    fwm.setPower(rp);

    //Then apply this to our rocket
    fw.setFireworkMeta(fwm);
    }
    }}}

    private Color getColor(int i) {
    Color c = null;
    if(i==1){
    c=Color.AQUA;
    }
    if(i==2){
    c=Color.BLACK;
    }
    if(i==3){
    c=Color.BLUE;
    }
    if(i==4){
    c=Color.FUCHSIA;
    }
    if(i==5){
    c=Color.GRAY;
    }
    if(i==6){
    c=Color.GREEN;
    }
    if(i==7){
    c=Color.LIME;
    }
    if(i==8){
    c=Color.MAROON;
    }
    if(i==9){
    c=Color.NAVY;
    }
    if(i==10){
    c=Color.OLIVE;
    }
    if(i==11){
    c=Color.ORANGE;
    }
    if(i==12){
    c=Color.PURPLE;
    }
    if(i==13){
    c=Color.RED;
    }
    if(i==14){
    c=Color.SILVER;
    }
    if(i==15){
    c=Color.TEAL;
    }
    if(i==16){
    c=Color.WHITE;
    }
    if(i==17){
    c=Color.YELLOW;
    }


    return c;
    }
    return true;
    }
    return false;}
    }

    can sombody please help me fix this!
     
  2. Offline

    SmooshCakez

    farting777

    1. Don't just paste your code, use
      Code:java
      1. [syntax=java][/syntax]
    2. You have a random bracket closing on the 2nd to last line.
    3. Don't use all those ifs, use a switch instead. (No difference, just to make the code look cleaner)
    4. It'd help to indent your code correctly. Ctrl+Shift+F if you're using Eclipse.
    5. Replace Logger.getLogger("Minecraft") with getLogger(); <-- Use the plugin logger
    6. Is there any reason you have a private PlayerLevelChangeEvent event; just sitting there, uninitialized?
     
    Bammerbom likes this.
  3. Offline

    mythbusterma

    SmooshCakez

    Switch is more efficient, as it will break after the comparison, if you do it right. Not that the performance difference is significant.

    farting777

    The solution to your problem is to learn Java. Then try again.
     
  4. Offline

    farting777

    SmooshCakez
    I'm keeping the ifs
    the playerlevelchange is there to prevent an error but i dont know why its there
    the random bracket is to prevent errors too
    i am using eclips and did the ctrl + shift + f but didnt help
    and also is the logger for the plugin bukkit? or not

    i fixed it i was right
    :)

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

    teej107

    • There is no reason to have an uninitialized variable (PlayerLevelChangeEvent, Main).
    • The getLogger() method provides you with the plugin's own personal logger. Don't use Minecraft's logger. That is Minecraft's logger.
    • All your if statements with getColor could be reduced into a for loop.
    • Also you can't declare a method inside another method (getColor).
    • Your code also has other errors in it like the trace of copied code. Use the Bukkit plugin tutorial rather than some bad developer's tutorial video.
    Please learn and understand Java before you start making plugins. Java is the language you are using when you develop plugins. Bukkit is just an API. It's a lot easier to learn Java first then learn an API rather than attempting to understand both simultaneously. You should always learn the language you are writing in.
     
    mythbusterma likes this.
Thread Status:
Not open for further replies.

Share This Page