Player name errors

Discussion in 'Plugin Development' started by Hex_27, Sep 25, 2014.

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

    Hex_27

    I want to create a plugin, where when anyone who consumes anything will get a configured effect. This is my code:
    Show Spoiler

    package me.leothepro.foodeffects;

    import java.util.List;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerItemConsumeEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class Main extends JavaPlugin implements Listener{

    public void onEnable(){
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    getConfig().options().copyDefaults(true);
    saveConfig();
    }

    //Note there is no need to make a nested class
    //If you go back and look at what you had, you can work out what we mean.
    @EventHandler
    public void onPlayerEatFoodEvent(PlayerItemConsumeEvent event) {
    Player p = event.getPlayer();
    List<String> a = getConfig().getStringList("effect");
    List<String> b = getConfig().getStringList("time");
    List<String> c = getConfig().getStringList("amplifier");

    if (p.hasPermission("foodeffects.use")|| p.isOp())
    {
    //regen Potion Effect (20 ticks = 1 second)
    String str = "effect" + " " + p + " " + a + " " + b + " " + c;
    p.addPotionEffect(new PotionEffect(PotionEffectType.a, b, c));
    } else {
    p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 0, 1));
    }

    }
    }

    The line in bold is the problematic line. How do I set the potion type as variable "a"?
     
  2. Offline

    mythbusterma

    Hex_27

    You don't have to or it with Player#isOp(), default permissions will grant ops the permission. PotionEffectType is an enum, use it like one.

    Correction, static constant.
     
  3. Offline

    Nateb1121

    Hex_27

    mythbusterma is right, it also looks like you're just expecting someone to hand you code. I could be wrong.


    Code:java
    1. //Note there is no need to make a nested class
    2. //If you go back and look at what you had, you can work out what we mean.
    3. @EventHandler
    4. .
    5. .
    6. .
    7.  


    is a direct copy from one of your previous threads, be sure you understand why you're using what you're using.

    In the spirit of learning here's what I'd do if you wanted to keep the system like you want:
    • Make a getting method, takes a name
    • Have it be a switch
    • Based on the name return the enum you need
    • Profit?
    See what you can do with that. Happy coding.
     
  4. Offline

    mythbusterma

    Nateb1121

    I don't think there's any profit to be had here.

    Learn Java, that is the best advice I can give you, Hex_27
     
    Nateb1121 likes this.
  5. Offline

    Hex_27

    Lol. Actually, I was expecting someone to give me the code. I would try to solve a problem for hours, before posting for help on a forum. So the "learn yourself" thing wouldn't really work out.. cause I've already been trying ._. Also, it's close to my exams, and I won't be able to learn Java any time soon. I learned the basics of coding plugins by the correcting help in eclipse and also by seeing other's codes. So, yes I learn by people giving me the codes directly.
     
  6. Offline

    dsouzamatt

    So you are trying to learn Java; you're learning through copying and pasting bits of code from other people. Although you might be able to get away with this for a little while, it's no substitute for taking the time to learn the language properly, through one of the many sets of tutorials available. If it's close to your exams, take a break from programming and spend that same time studying instead. In the meantime, if you need this plugin finished quickly you can make a thread under the "plugin requests" category and have someone else make it for you.
     
    adventuretc likes this.
  7. Offline

    Hex_27

    alright
     
  8. Offline

    ChipDev

    Class, this is a great example of why you should LEARN JAVA before Bukkit API.
     
    Nateb1121 likes this.
  9. Offline

    CursedReaper

    Hex_27 b and c are integers
     
  10. Offline

    Hex_27

    so how do I define a as a word?
     
  11. Offline

    Nateb1121

    You can define a as a word by declaring it as the type of String.

    But really, I can see what you're trying to do, but you're NOT going to be able to do something like this:

    Code:
    String a = "JUMP";
    Player p = Bukkit.getPlayer("Nateb1121");
    p.addPoitioneffect(PotionEffect.a, b, c, d ... );
    
    Java doesn't work that way. Like I said,
     
  12. Offline

    Hex_27

    I'm a rookie. I ignored the 3 step thing cos I have no idea what it means.
     
  13. Offline

    teej107

    Hex_27

    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.

    As Nateb1121 said, Java doesn't work that way. If you have no idea what any of his steps mean, you should take my advice, ChipDev advice, dsouzamatt advice, and mythbusterma advice.
     
  14. Offline

    Hex_27

    You're changing the topic. I get that I needa learn Java, but right now, I want to make this plugin. The topic is about the plugin. So guys stop putting comments about learning Java because I already get that part. I want to know how to fix MY code.
     
  15. That would be the best.
     
  16. Offline

    Hex_27

    No. I want the experience.
     
  17. Offline

    Hex_27

    I still need help with this.
     
  18. Offline

    fireblast709

    (it actually isn't, they are constants)
    For compatibility with Java 6 and to make it easier to expand, use a Map :p

    Hex_27 simply put, there is no constant 'a' in PotionEffectType. You will have to manually convert from Strings to PotionEffectType (and how that's done is up to you)

    For reference: http://jd.bukkit.org/dev/apidocs/org/bukkit/potion/PotionEffectType.html
     
    Nateb1121 likes this.
  19. Offline

    Hex_27

    It's all fine. I found out how. BY READING SOMEBODY'S CODE. :mad:

    <sarcasm>So right now, I'll just clap for those who spammed "go learn java".</sarcasm>

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

    fireblast709

    You must be able to understand the basics of a programming language if you intend to use it. There are no shortcuts. Reading someone else's code won't teach you the skills to solve the problems next time.
     
    es359 likes this.
  21. Offline

    es359


    You don't learn that way. Actually you will never learn that way.
    They are trying to teach you.
     
  22. Offline

    Hawktasard

    Basic Java knowledge, and messing around with the API (maybe some tutorials too) is what you need to learn Bukkit.
     
  23. Offline

    Hex_27

    Still lecturing me. Wow. I've already explained that I don't want to see this crap any more.
     
  24. Offline

    mythbusterma

    Hex_27

    Don't expect to get any help ever again here. You didn't "learn something from looking at someone's code," you copied it. Don't expect us to help you when it doesn't work.
     
Thread Status:
Not open for further replies.

Share This Page