Hi, i got error in eclipse with my code and don't now what to do. Insert the code to see the errors. Code:java public void onEnable() {this.getServer().getPluginManager().registerEvents(this, this);} public Location[] circleFrom(Location l) {List<Location> returnList = new ArrayList<Location>();for(int x = 2; x>=-2; x--){for(int z = 2; z>=-2; z--){for(int y = 0; y>=1; y++){if(!(Math.abs(z)==1&&x==0)||!(Math.abs(x)==1&&z==0)||x!=z){returnList.add(new Location(l.getWorld(), l.getX()-x, l.getY()+y, l.getZ()-z));}}}}return returnList.toArray(new Location[returnList.size()]);} @EventHandlerpublic void gandalf(PlayerInteractEvent e) {Player p = e.getPlayer();Action a = e.getAction();if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {if (p.getItemInHand().getType() == Material.STICK) { } Location location=p.getLocation();for(int i = 0; i<circleFrom(location).length; i++){Location l = circleFrom(location);Material changeTo = Material.SPONGE;//Change this to whatever you want, IDC. If you want to get the//Block under the location, create a loop that will go locations //if the locations block is air continue, if not break and use that one.new BukkitRunnable(){public void run(){l.getBlock().setType(changeTo);}}.runTaskLater(this, i*2);//i*20 = (i) seconds}new BukkitRunnable(){public void run(){for(Location l : circleFrom(location)){l.getBlock().setType(Material.AIR);}}.runTaskLater(this, 3.8);//2 seconds + 18 blocks that each takes 0.1}} }}
1) Which line are you getting the error on? and what if you hover over the red line in eclipse. It will say what is the error is, What does it say? 2) You should post the whole class with all your imports, importing from the wrong location can cause errors as well.
Code:java //Whole codepackage me.gandalf; import java.util.ArrayList;import java.util.List; import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.scheduler.BukkitRunnable; public class Main extends JavaPlugin implements Listener { public void onEnable() {this.getServer().getPluginManager().registerEvents(this, this);} public Location[] circleFrom(Location l) {List<Location> returnList = new ArrayList<Location>();for(int x = 2; x>=-2; x--){for(int z = 2; z>=-2; z--){for(int y = 0; y>=1; y++){if(!(Math.abs(z)==1&&x==0)||!(Math.abs(x)==1&&z==0)||x!=z){returnList.add(new Location(l.getWorld(), l.getX()-x, l.getY()+y, l.getZ()-z));}}}}return returnList.toArray(new Location[returnList.size()]);} @EventHandlerpublic void gandalf(PlayerInteractEvent e) {Player p = e.getPlayer();Action a = e.getAction();if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {if (p.getItemInHand().getType() == Material.STICK) { } Location location=p.getLocation();for(int i = 0; i<circleFrom(location).length; i++){Location l = circleFrom(location);Material changeTo = Material.SPONGE;//Change this to whatever you want, IDC. If you want to get the//Block under the location, create a loop that will go locations //if the locations block is air continue, if not break and use that one.new BukkitRunnable(){public void run(){l.getBlock().setType(changeTo);}}.runTaskLater(this, i*2);//i*20 = (i) seconds}new BukkitRunnable(){public void run(){for(Location l : circleFrom(location)){l.getBlock().setType(Material.AIR);}}.runTaskLater(this, 3.8);//2 seconds + 18 blocks that each takes 0.1}} }} Error: Location l = circleFrom(location); - cannot convert from Location[] to Location Error: }.runTaskLater(this, 3.8); - syntax error on token ".", { expected' Error: l.getBlock().setType(changeTo); - Cannot refer to a non-final variable l inside an inner class defined in a different method Error: } - Syntax error, insert "}" to complete Statement When i insert more "}" it just give me more errors
Error #1: Line 49 say l is a location, but your method returns an array of locations. Error #2: In line 63, you can't have a delay of 3.8. In minecraft, all time is recorded in ticks, or 20ths of a second. You can't have a delay of 3.8 ticks. If you wanted a delay of 3.8 seconds, that number should be (3.8*20=) 76. Error #3: Because a runnable is actually a different class (or something like that), you can't modify variables from the class in it. Java wants you to promise that you won't by adding final to the beginning of line 50. Error #4: I really can't tell. I think you have too many }. Can't you tell us what line this was on? Error #5: You're not supposed to make a new thread on bukkit for the same problem. If you're planning on actually coding more plugins, you should be able to fix these errors on your own, at least the first one. That one was waaay too simple.
Try inserting a } on line 62. Honestly though, you should take classes, or you'll run into stuff like the first error every time. I'm a noob too, but you have to understand the difference between location[] and location: location may be just one location. location[] contains some locations: location[1] may be a location. location[2] may be another location. same as the difference between int and int[], or string and string[], or nearly anything!