restarting a count down

Discussion in 'Plugin Development' started by matanrak, Jun 12, 2014.

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

    matanrak

    i got a count down that restart if there are not enough players , but i can't figure how to restart it..
    my restarting code:
    Code:java
    1. number = 6;
     
  2. matanrak your restarting code is number = 6, Im not sure how can we help you...
     
  3. Offline

    matanrak

    it
    nope
    thats is just the part that adds the number to the count down, not all the code
     
  4. thats what youre showing us, your restarting code is "6 = number", if you were to show us your code you would get help much faster.
     
  5. Offline

    matanrak

    basicly i am asking how can i add a number to an int
     
  6. matanrak youre asking how can you add 2 integers together?....
    Integer f = 0;
    Integer a = 3;
    Integer i = 2;
    Integer l = 1;
    f + i; //adding i(2) to f (0)
    example: String s = "Numbers " + f + a + i + l;

    EDIT: one more easier example, you can simply do number + 10,
     
  7. Offline

    matanrak

    no i ask how to add "60" to the int "number" i had a lot of trouble with that
     
  8. matanrak I just told you, number + 60; I cant say it simpler than that.. :eek:
     
  9. Offline

    matanrak

    XD XD I never tried that one before

    can you take a look at this? this is a game ending code that i am working on and the } are messed up i think so i am getting a lot of errors
    code:
    Code:
     
    @EventHandler
    public void gamedning(PlayerDeathEvent event) {
    Player p = (Player) event.getEntity();
     
     
     
     
    if(players.size() == 2){
        Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.DARK_RED + "The Game Has Ended!");
        Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.DARK_RED + "Server Restarting in 10 seconds!");
     
        int number2 = 20;
     
    new BukkitRunnable(){
     
        private Location loc = new Location(cw, 2754.52424, 64, -1029.70000);   
       
        public void run(){
             
            int number2 = 20;
       
                  if(player1.getWorld().equals("map1"));{
               
          player1.setLevel(number2);
            }
           
          if((number2 < 20) && (number2 > 0)) {
             
     
                        if(player.getWorld().equals("map1"));{
                    player.getWorld().playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 17.0F); 
                    player.getWorld().playSound(player.getLocation(), Sound.LEVEL_UP , 1.0F, 17.0F);
                   
                   
                   
                    player.getWorld().playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 17.0F); 
                    player.getWorld().playSound(player.getLocation(), Sound.LEVEL_UP , 1.0F, 17.0F);
                    final Firework f = (Firework)player.getWorld().spawn(player.getLocation(), Firework.class);
                    FireworkMeta fm = f.getFireworkMeta();
                    fm.addEffect(FireworkEffect.builder()
                                    .flicker(true)
                                    .trail(true)
                                    .with(Type.BALL_LARGE)
                                    .withColor(Color.AQUA)
                                    .withFade(Color.RED)
                                    .build());
                    fm.setPower(1);
                    f.setFireworkMeta(fm);
                   
                    final Firework f2 = (Firework)player.getWorld().spawn(player.getLocation(), Firework.class);
                    FireworkMeta fm2 = f2.getFireworkMeta();
                    fm2.addEffect(FireworkEffect.builder()
                                    .flicker(true)
                                    .trail(true)
                                    .with(Type.BALL_LARGE)
                                    .withColor(Color.ORANGE)
                                    .withFade(Color.MAROON)
                                    .build());
                    fm2.setPower(0);
                    f2.setFireworkMeta(fm2);
                    player.getInventory().getItemInHand();
                    player.getWorld().playSound(player.getLocation(), Sound.CREEPER_HISS, 1, 0);
                    Location los = player.getLocation();
                 
                   
                   
                   
                   
                       
               
              }
          }
     
             
      if(number2 != -1){
         
      if(number2 !=0){
          number2--;
     
      }else {
         
               
             
                      Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.GREEN + "You were given 50 tokens!");
                   
                 
                 
              }
         
     
            //  Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.GRAY.toString() + "The Minataur"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.GREEN + "Your now back in the arcade!");
     
           
              this.cancel();
         
     
     
             
          }
       
        }
        }
          }.runTaskTimer(this, 0L, 20L);
    }
     
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  10. matanrak Why trying to use Bukkit if you dont know Java and basic programming?
     
  11. Offline

    matanrak

    i do know java but this code is messed up can you help me , i am now writing one of my first big bukkit plugin and need some help
     
  12. matanrak [​IMG]
    if you do not know how to add 2 integers together its means you do not know Java (BASIC Java).
    that code is messed up because you didnt learn Java before trying to program in java.
    youre doing something like that: Location los = players.getLocation(), youre not even using that location. why do you need it? and what messed up with that code?
    EDIT: again, one of your lines: player.getInventory().getItemInHand(); .....
    EDIT 2: youre comparing world to a string.
    EDIT 3: private Location loc = new Location(cw, 2754,52424, 64, -1029.70000); youre not doing with that location anything.
    *Im sure that youre not showing us your full code (I dont have any problem with that, I respect that you dont want to show it) but I will suggest you removing some of the simple stuff that just dont match, you have in your private location the world CW, theres nothing about this world
     
  13. Offline

    matanrak

    that code is an old code used in on of my other plugins , i am now changing it to fit to my new plugin
    the world cw in a world used in another area

    Ok the add int code did not worked it gave an error... here is my full code:
    Code:
                        new BukkitRunnable(){
                           
     
        int number = 20;
                            private Location locspawnp;
                            private Location locspawnm;
                          World map1 = Bukkit.getWorld("map1");
                          public void run(){
               
                             
                             
                             
     
     
                     
                     
                                    for(Player player1 : map1.getPlayers() ){
                                          if(player1.getWorld().equals("map1"));{
                                  player1.setLevel(number);
                                  Bukkit.getPluginManager().getPlugin("Survival Games").getConfig().set("games", 0);
                                    }
                                    }
                                if((number < 6) && (number > 0)) {
                                    for(Player player : map1.getPlayers() ){
           
                                                if(player.getWorld().equals("map1"));{
                                            player.getWorld().playSound(player.getLocation(), Sound.NOTE_PLING, 1.0F, 17.0F); 
                                            player.getWorld().playSound(player.getLocation(), Sound.LEVEL_UP , 1.0F, 17.0F);
                                                }
                                       
                                    }
                                }
                         
                 
                  if(number != -1){
                     
                  if(number !=0){
                      number--;
                 
                  }
                      else if (Bukkit.getOnlinePlayers().length > 1){
           
                   
                          Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.GRAY + "------------------------------------");
                          Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.DARK_RED + "The Game Has Started");
                          Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.GREEN + "Find loot crates (Note Blocks N JukeBox");
                          Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.GREEN + "And Fight Your Way To The Win!");
                          Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.GREEN + "Every One is On Thier Own Now May God");
                          Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.GREEN + "Help Us All.");
                          Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.GREEN + "20 Second until invincibility Ends");
                          Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.GRAY + "------------------------------------");
                     
                             
                   
           
                      for(Player player : map1.getPlayers() ){
                          players.add(player.getName());
                       
                       
                                 
                   
                     
                     
                   
                          this.locspawnp = new Location(map1, 100, 109, 24);   
     
                          player.teleport(this.locspawnp);
                        this.cancel();
                                     
                      }
                     
                    //  int random = new Random().nextInt(Bukkit.getOnlinePlayers().length);
     
              //    Player player2 = Bukkit.getOnlinePlayers()[random];
                       
                     
                        World map1 = Bukkit.getWorld("map1");
                   
                        //player2.teleport(this.locspawnm);                         
                       
                      ItemStack snow = new ItemStack(Material.IRON_AXE , 1);                                       
                        snow.addUnsafeEnchantment(Enchantment.DURABILITY, 10000);
                        ItemStack skull = new ItemStack(Material.SKULL, 1);
                      ItemMeta meta = snow.getItemMeta(); 
                           
               
                   
             
     
                      Bukkit.getPluginManager().getPlugin("Survival Games").getConfig().set("games", 1);
                     
                          this.cancel();
       
                       
         
                      }else {
                            Bukkit.broadcastMessage(ChatColor.DARK_GRAY.toString() + "[" + ChatColor.AQUA.toString() + "The Survival Games"+ ChatColor.DARK_GRAY.toString() + "] " + ChatColor.DARK_RED + "You cant play alone! Restarting Count Down!");
                        number + 60
               
                         
                            this.cancel();
                  }
                  }
                 
            }
     
                         
                         
               
               
               
                }.runTaskTimer(this, 0L, 20L);
     
           
           
           
           
           
           
            
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  14. matanrak Im wondering, is it spam? do you try to make fun of us?
    the "code" to add integer to an integer?...
    pro tip: try learn bit (really, bit, not much) of Java before coming here, it will help you more than you think it will.
    EDIT: its didnt work because you did this,
    number + 60
     
  15. Offline

    matanrak

    i will but can you please help me?
     
  16. matanrak
    NO I can not help you if you are not helping yourself.
     
  17. Offline

    matanrak

    i am right now learning java as you said but if i do "number + 10"
    it gives me an error...
    saying: say text error on token "+", invalid assignment operator
     
  18. matanrak if you still dont know the answer you arent learning, youre just playing with bukkit, if you would learn the basic of programming you would know that you have to put ;
    I dont see why to keep doing this, put ";" at the end, example: number + otherNumber;
     
  19. Offline

    matanrak

    i do know to add ; but this was just an example this happened with the ;

    ok i am trying :
    Code:
     number + r;
                       
    int r = 20;
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  20. Offline

    cheddar262

    First of all, if it's in that order, then r wouldn't be defined at the point you add to the number.

    Similarly, if it were in the correct order, all you're doing is just adding two numbers together and that addition isn't stored at all. The process of adding them together basically wasted because it isn't stored into a variable again.
     
  21. Offline

    matanrak

    the int r is defined in my code before the int adding but can you please help me with this i tried to fix this for a long time and i really need some help,

    ok i tried
    Code:
         
                          number++;
    but still nothing

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

    cheddar262

    As people have mentioned before. It's probably best if you learn this yourself. There are some major parts you're missing. I've already explained to you the issue with your "number + r;" If you can't understand my explanation or figure out why it can't work, you may want to review a bit of the variable assignment part of java.
     
    Someone_Like_You likes this.
  23. Offline

    matanrak

    i did but still i can not see how to fix it...

    and why should i store it some where?
    do i need to store it in a hashmap?

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

    cheddar262

    All you're doing with "number + r" is adding the two values together and discarding the result. No values change anywhere with that.
     
    Someone_Like_You likes this.
  25. Offline

    matanrak

    i will learn java right now but please just help me here so i can not do this mistake again...yes i am new to java and all so please help me get better

    so how can i change it

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

    cheddar262

    There are two ways to increment a variable, which I believe is what you're trying to do:
    "number += r" or
    "number = number + r"
    this assigns the value of "number + r" back to "number"
     
    Someone_Like_You likes this.
  27. Offline

    Aqua

    int r = ADDITION;
    number += r;
    matanrak
     
  28. Offline

    Dubehh

  29. Offline

    Maximvdw

    Yoda: You will succeed by learning young padawan.

    Better to learn it first before asking what is wrong?
     
  30. Offline

    matanrak

    thanks for that advise :D i fixed the problem
     
Thread Status:
Not open for further replies.

Share This Page