I want to create a plugin, where when anyone who consumes anything will get a configured effect. This is my code: Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide 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"?
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.
Hex_27 mythbusterma is right, it also looks like you're just expecting someone to hand you code. I could be wrong. Code:java //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... 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.
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
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.
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.
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,
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.
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.
(it actually isn't, they are constants) For compatibility with Java 6 and to make it easier to expand, use a Map 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
It's all fine. I found out how. BY READING SOMEBODY'S CODE. <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.
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.
Basic Java knowledge, and messing around with the API (maybe some tutorials too) is what you need to learn Bukkit.
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.