I can't figure out why I'm getting this error

Discussion in 'Plugin Development' started by zippyclutch, Apr 8, 2017.

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

    zippyclutch

    Hi. I'm coding a plugin that allows for a perk. If a player has the permission SimpleVIPPerks.vipsta, they will receive speed if they have slowness (to counter the slowness). Here's my code:

    package me.StalkerPerk;

    import org.bukkit.entity.Entity;

    import org.bukkit.entity.LivingEntity;

    import org.bukkit.entity.Player;

    import org.bukkit.plugin.java.JavaPlugin;

    import org.bukkit.potion.PotionEffect;

    import org.bukkit.potion.PotionEffectType;

    public class Main extends JavaPlugin {


    if (player.hasPotionEffect(PotionEffectType.SLOWNESS))

    if(!(player.hasPermission("SimpleVIPPerks.vipsta"))){

    LivingEntity player;

    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,-1,2));

    }

    }

    }

    ---------------------------------------
    I'm not sure what I did wrong, note I am very new to coding here. I get an error under the curly bracket in: public class Main extends JavaPlugin {

    and it says to me:
    Syntax error on token "{", { expected after this token

    But I'm not sure how to fix this.

    Any help is appreciated. Thanks in advance.
     
  2. Offline

    martian3333

    @zippyclutch
    For the specific error that you're talking about... you don't have a { after your first IF statement

    You could combine your IF statements to


    if (player.hasPotionEffect(PotionEffectType.SLOWNESS) && !player.hasPermission("SimpleVIPPerks.vipsta")){
     
  3. Offline

    zippyclutch

    I'm still getting the same error on the { after JavaPlugin. But thanks for this help.
     
  4. Offline

    martian3333

    @zippyclutch
    Honestly I've never seen a plugin without an onEnable and onDisable. Have you looked over http://bukkit.gamepedia.com/Plugin_Tutorial

    As it is you're trying to interact with an unknown player, before the plugin has been enabled, with no event or command indicating why anything should actually be happening.
     
  5. Offline

    zippyclutch

    I see what you mean. You said that I'm trying to interact with an unknown player. Should I add an onPlayerJoinEvent? Also, I added the onEnable thingy here. I've made two plugins in the past that have worked with just an @EventHandler and no onEnable, so I'm new to this side of things.

    package me.StalkerPerk;



    import org.bukkit.entity.LivingEntity;

    import org.bukkit.plugin.java.JavaPlugin;

    import org.bukkit.potion.PotionEffect;

    import org.bukkit.potion.PotionEffectType;

    public class Main extends JavaPlugin {
    @Override
    public void onEnable() {
    LivingEntity player;
    if (player.hasPotionEffect(PotionEffectType.SLOW))
    if(!(player.hasPermission("SimpleVIPPerks.vipsta"))){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,-1,2));

    }

    }


    }

    }
     
  6. Offline

    martian3333

    @zippyclutch

    I think you're going to need to use an event handler. Probably catch potion splash events and player consume events to see if they get slowness from drinking a potion or having one thrown at them.
     
  7. Offline

    zippyclutch

    Would you mind showing me what to do? What I tried didn't work.
     
  8. Offline

    Zombie_Striker

    @martian3333
    Plugins do not need onEnables or orDisables. You only need the on enable for registering executors or listeners, and you only really need onDisable for saving information. If your plugin does not do those things, you don't need those methods.

    @zippyclutch
    Have you ever officially learned Java before? It does not seem that way. You Need to know how to write programs in Java before working on Bukkit. If you do not have a tutorial already, pick one from the following link, learn Java, and then come back to bukkit.
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/
     
  9. Offline

    zippyclutch

    Thanks for the help. But really, I'm not asking if I need to learn Java or not. All I'm asking is how to fix this error. I've coded plugins before, and I have some experience. If nobody is going to help me here, I have other places I can ask.
     
  10. Offline

    Zombie_Striker

    @zippyclutch
    The issue with that is that you are not learning how to code, you just learning how to get the answers from other people. Because you would not be learning from it, you will continually come back here asking more questions similar to this. This has happened many times before, so that is why we do not spoonfeed code (something it seems you were asking for above) and always recommend you learn Java before working on bukkit.

    For your problem, you need to use these two events. Check if the potion used is slowness and if the player has slowness, and if so, remove the slowness and add speed.
    https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/entity/LingeringPotionSplashEvent.html
    https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerItemConsumeEvent.html
     
  11. Offline

    Horsey

    @Zombie_Striker
    tbh you can learn Java by learning Bukkit but yeah I agree, some background knowledge of Java is necessary since you aint gonna get peeps teaching you basic Java.
     
  12. Offline

    Zombie_Striker

    @Horsey
    Although you can, doing it that way will give you the same amount of knowledge as TheBCBroz (and will allow you to make the same mistakes as well).
     
Thread Status:
Not open for further replies.

Share This Page