Solved Creating Gandalf kit

Discussion in 'Plugin Development' started by Stackore, Apr 20, 2014.

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

    Stackore

    Hi, i got an idea and want to create a kit with the name "Gandalf" So basic when you rightclick with a stick, then a circle of blocks occur around the player 5 blocks high then after 5 seconds the circle disapear. I have no idea how to do this. But here is my code:
    Code:java
    1. @EventHandler
    2. public void gandalf(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. Action a = e.getAction();
    5. if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
    6. if (p.getItemInHand().getType() == Material.STICK) {
    7.  
    8. //the circle code

    And i want the circle to build up "block by block" not just that it spawns a circle
    Happy for help :)
     
  2. Offline

    Bobit

    I'm not going to code this for you, but I will tell you that the people who do will will need more parameters:

    -How do you want the circle to build up? Go around placing the first layer, then the next one?
    -How quickly do you want it to build up?
    -How wide do you want the circle to be?
    -Do you want this circle to bypass other blocks? (if there was a diamond block, delete it for the wall permanently, temporarily, or just leave it?)
     
    TigerHix and clmcd42 like this.
  3. Offline

    Stackore

    I want the circle to build up layer by layer on 2 seconds, 3 x 3 circle, yes bypass other blocks
     
  4. Offline

    Bobit

    Do you want to put the blocks back after the wall is removed?
    (You probably do, but that's harder to code)
     
  5. Offline

    Stackore

    Yes
     
  6. Offline

    Bobit

    One last thing, then I'm out of here:

    This is pretty basic. All you do is change the coords and put in a few blocks after a delay. If you don't know how to do this, maybe this should be in the "Plugin requests" section. This section is more for fixing bugs and small things.
     
  7. Offline

    Stackore

    Any help pls? :3
     
  8. Offline

    Bobit

    Stackore
    It's an unspoken rule on the forums that you don't post just so someone will notice within 24 hours of your last post.
     
  9. Offline

    NonameSL

    First, get the players X,Y,Z -
    Location l = p.getEyeLocation();
    double x = l.getX();
    double y = l.getY();
    double z = l.getZ();
    then, create new 18 locations around the player, which can be understanded from this simple drawing:
    [​IMG]
    The numbers like +2z or -1x are just the numbers we need to add or remove from the current X or current Z. The second layer is excactly like the first one but with +1Y. The block locations we don't want want are the locations where OR 1 of the variables(From the x and z) are 0 and the other is (1 or -1), or the locations where both variables are the same. So we need this method to get all the locations in this drawing but the ones we dont want:
    Code:java
    1. public Location[] circleFrom(Location l){
    2. List<Location> returnList = new ArrayList<Location>();
    3. for(int x = 2; x>=-2; x--){
    4. for(int z = 2; z>=-2; z--){
    5. for(int y = 0; y>=1; y++){
    6. if(!(Math.abs(z)==1&&x==0)||!(Math.abs(x)==1&&z==0)||x!=z){
    7. returnList.add(new Location(l.getWorld(), l.getX()-x, l.getY()+y, l.getZ()-z));
    8. }
    9. }
    10. }
    11. }
    12. return returnList.toArray(new Location[returnList.size()]);
    13. }


    If you want to spawn it block by block, that can be done - lets just do this in a delay of 0.1 seconds between spawning of block.
    Now that we have our locations, what we want to do is to set types for each location when the stick is clicked:
    (We are declaring Location location outside the event because we need it for the BukkitRunnable at the end.
    Code:java
    1.  
    2. Location location=p.getLocation();
    3. for(int i = 0; i<circleFrom(location).length; i++){
    4. Location l = circleFrom(location)[I];[/I]
    5. [I] Material changeTo = Material.SPONGE;//Change this to whatever you want, IDC. If you want to get the[/I]
    6. [I] //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.[/I]
    7. [I] new BukkitRunnable(){[/I]
    8. [I] public void run(){[/I]
    9. [I] l.getBlock().setType(changeTo);[/I]
    10. [I] }[/I]
    11. [I] }.runTaskLater(this, i*2);//i*20 = (i) seconds[/I]
    12. [I]}[/I]
    13. [I]new BukkitRunnable(){[/I]
    14. [I] public void run(){[/I]
    15. [I] for(Location l : circleFrom(location)){[/I]
    16. [I] l.getBlock().setType(Material.AIR);[/I]
    17. [I] }[/I]
    18. [I] }.runTaskLater(this, 3.8);//2 seconds + 18 blocks that each takes 0.1[/I]
    19. [I]}[/I]
    20. [I][/I]

    Ta da!
     
    AoH_Ruthless and Tehmaker like this.
  10. Offline

    Stackore

    Can you please insert that above my code:
    Code:java
    1. @EventHandler
    2. public void gandalf(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. Action a = e.getAction();
    5. if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
    6. if (p.getItemInHand().getType() == Material.STICK) {


    But thanks for the help :)
     
  11. Offline

    NonameSL

    Stackore I dont understand why that is needed... There is one method that obviously doesn't belong in a void, and another piece of code that obviously belongs in a method and cant just float in a class.
     
  12. Offline

    Stackore


    Code:java
    1. //i did this but got error in eclipse {
    2. public Location[] circleFrom(Location l)List<Location> returnList = new ArrayList<Location>();
    3. for(int x = 2; x>=-2; x--){
    4. for(int z = 2; z>=-2; z--){
    5. for(int y = 0; y>=1; y++){
    6. if(!(Math.abs(z)==1&&x==0)||!(Math.abs(x)==1&&z==0)||x!=z){
    7. returnList.add(new Location(l.getWorld(), l.getX()-x, l.getY()+y, l.getZ()-z));
    8. }
    9. }
    10. }
    11. }
    12. return returnList.toArray(new Location[returnList.size()]);
    13. }
    14.  
    15. @EventHandler
    16. public void gandalf(PlayerInteractEvent e) {
    17. Player p = e.getPlayer();
    18. Action a = e.getAction();
    19. if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
    20. if (p.getItemInHand().getType() == Material.STICK) {
    21.  
    22. Location location=p.getLocation();
    23. for(int i = 0; i<circleFrom(location).length; i++){
    24. Location l = circleFrom(location)[I];[/I]
    25. [I] Material changeTo = Material.SPONGE;//Change this to whatever you want, IDC. If you want to get the[/I]
    26. [I] //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.[/I]
    27. [I] new BukkitRunnable(){[/I]
    28. [I] public void run(){[/I]
    29. [I] l.getBlock().setType(changeTo);[/I]
    30. [I] }[/I]
    31. [I] }.runTaskLater(this, i*2);//i*20 = (i) seconds[/I]
    32. [I]}[/I]
    33. [I]new BukkitRunnable(){[/I]
    34. [I] public void run(){[/I]
    35. [I] for(Location l : circleFrom(location)){[/I]
    36. [I] l.getBlock().setType(Material.AIR);[/I]
    37. [I] }[/I]
    38. [I] }.runTaskLater(this, 3.8);//2 seconds + 18 blocks that each takes 0.1[/I]
    39. [I]}[/I]
    40.  
    41.  
    42. }
    43. }
    44. }
    45. }



    This part gives me much errors:
    Code:java
    1. Location location=p.getLocation();
    2. for(int i = 0; i<circleFrom(location).length; i++){
    3. Location l = circleFrom(location)[I];[/I]
    4. [I] Material changeTo = Material.SPONGE;//Change this to whatever you want, IDC. If you want to get the[/I]
    5. [I] //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.[/I]
    6. [I] new BukkitRunnable(){[/I]
    7. [I] public void run(){[/I]
    8. [I] l.getBlock().setType(changeTo);[/I]
    9. [I] }[/I]
    10. [I] }.runTaskLater(this, i*2);//i*20 = (i) seconds[/I]
    11. [I]}[/I]
    12. [I]new BukkitRunnable(){[/I]
    13. [I] public void run(){[/I]
    14. [I] for(Location l : circleFrom(location)){[/I]
    15. [I] l.getBlock().setType(Material.AIR);[/I]
    16. [I] }[/I]
    17. [I] }.runTaskLater(this, 3.8);//2 seconds + 18 blocks that each takes 0.1[/I]
    18. [I]}[/I]
    19. [I][/I]


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

    TryB4

  14. Offline

    NonameSL

    Stackore as TryB4 said, remove the
    Code:
    [I]
    and
    Code:
    [/I]
    , they mustve been added automatically by the
    Code:
    [syntax=java][/syntax]
     
  15. Offline

    Stackore

    I don't know why, but i still get errors, can u send the code again without the java "code"
     
  16. Offline

    Konkz

    I use this to get circles, I forgot the author so I can't give the credits.

    PHP:
    public static List<Locationcircle(Location locint radiusint heightboolean hollowboolean sphereint plusY) {
            List<
    Locationcircleblocks = new ArrayList<Location>();
     
            
    int cx loc.getBlockX();
            
    int cy loc.getBlockY();
            
    int cz loc.getBlockZ();
     
            for (
    int x cx radius<= cx radiusx++) {
                for (
    int z cz radius<= cz radiusz++) {
                    for (
    int y = (sphere cy radius cy); < (sphere cy radius cy height); y++) {
                        
    double dist = (cx x) * (cx x) + (cz z) * (cz z) + (sphere ? (cy y) * (cy y) : 0);
                        if (
    dist radius radius && !(hollow && dist < (radius 1) * (radius 1))) {
                            
    Location l = new Location(loc.getWorld(), xplusYz);
                            
    circleblocks.add(l);
                        }
                    }
                }
            }
     
            return 
    circleblocks;
        }
     
    Plugers11 likes this.
  17. Offline

    Stackore

    Do you now how to do this? but with no errors!
    Code:java
    1. Location location=p.getLocation();
    2. for(int i = 0; i<circleFrom(location).length; i++){
    3. Location l = circleFrom(location)[I];[/I]
    4. [I] Material changeTo = Material.SPONGE;//Change this to whatever you want, IDC. If you want to get the[/I]
    5. [I] //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.[/I]
    6. [I] new BukkitRunnable(){[/I]
    7. [I] public void run(){[/I]
    8. [I] l.getBlock().setType(changeTo);[/I]
    9. [I] }[/I]
    10. [I] }.runTaskLater(this, i*2);//i*20 = (i) seconds[/I]
    11. [I]}[/I]
    12. [I]new BukkitRunnable(){[/I]
    13. [I] public void run(){[/I]
    14. [I] for(Location l : circleFrom(location)){[/I]
    15. [I] l.getBlock().setType(Material.AIR);[/I]
    16. [I] }[/I]
    17. [I] }.runTaskLater(this, 3.8);//2 seconds + 18 blocks that each takes 0.1[/I]
    18. [I]}[/I]
    19.  

    Code:
    I got error without [I] or [/I] too
     
  18. Offline

    MrInspector

    That should fix the format.
     
  19. Offline

    Stackore

    Still got errors but mayby i place it wrong or something, could you please insert that to my code?
    Code:java
    1. ublic class Main extends JavaPlugin implements Listener {
    2.  
    3. public void onEnable() {
    4. this.getServer().getPluginManager().registerEvents(this, this);
    5. }
    6.  
    7.  
    8. public Location[] circleFrom(Location l) {
    9. List<Location> returnList = new ArrayList<Location>();
    10. for(int x = 2; x>=-2; x--){
    11. for(int z = 2; z>=-2; z--){
    12. for(int y = 0; y>=1; y++){
    13. if(!(Math.abs(z)==1&&x==0)||!(Math.abs(x)==1&&z==0)||x!=z){
    14. returnList.add(new Location(l.getWorld(), l.getX()-x, l.getY()+y, l.getZ()-z));
    15. }
    16. }
    17. }
    18. }
    19. return returnList.toArray(new Location[returnList.size()]);
    20. }
    21.  
    22. @EventHandler
    23. public void gandalf(PlayerInteractEvent e) {
    24. Player p = e.getPlayer();
    25. Action a = e.getAction();
    26. if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
    27. if (p.getItemInHand().getType() == Material.STICK) {
    28.  
    29. }
    30. }
    31. }
    32. }
     
  20. Offline

    MrInspector

    You're forgetting the 'p' in public, it says ublic, maybe that's your error?
     
  21. Offline

    L33m4n123

    A good start would be telling what the error is?
     
  22. Offline

    Stackore

    This part in eclipse
    Code:java
    1. Location location=p.getLocation();
    2. for(int i = 0; i<circleFrom(location).length; i++){
    3. Location l = circleFrom(location);
    4. Material changeTo = Material.SPONGE;//Change this to whatever you want, IDC. If you want to get the
    5. //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.
    6. new BukkitRunnable(){
    7. public void run(){
    8. l.getBlock().setType(changeTo);
    9. }
    10. }.runTaskLater(this, i*2);//i*20 = (i) seconds
    11. }
    12. new BukkitRunnable(){
    13. public void run(){
    14. for(Location l : circleFrom(location)){
    15. l.getBlock().setType(Material.AIR);
    16. }
    17. }.runTaskLater(this, 3.8);//2 seconds + 18 blocks that each takes 0.1
    18. }
    19.  
    20. Syntax error on token "." { expected - }.runTaskLater(this, 3.8);
    21. Multiple markers at this line
    22. - Cannot refer to a non-final variable l inside an inner class defined in
    23. a different method
    24. - Cannot refer to a non-final variable changeTo inside an inner class
    25. defined in a different method - l.getBlock().setType(changeTo);
    26.  
    27. cannot convert from Location[] to Location - Location l = circleFrom(location);
    28.  
     
  23. Offline

    Bobit

    It would help a ton of you told us what part of that code netbeans eclipse doesn't like, and what it has to say about it.
     
  24. Offline

    NonameSL

  25. Offline

    Stackore

  26. Offline

    NonameSL

    Make Location location outside the method, and instead of Location location = p.getLocation(); just do location = p.getLocation();

    BTW, is this code in your main class?
     
Thread Status:
Not open for further replies.

Share This Page