i have some bag in my code

Discussion in 'Spigot Plugin Development' started by bmwdev, Nov 4, 2018.

  1. in game timer not down what problem

    Code (Java):
        public static int timer = 900;  //min
        public static int sec = 60;  // sec
     
        [USER=32110]@Override[/USER]
        public void run() {
            for (Player all : Bukkit.getOnlinePlayers()) {
                if (Arrays.inSologameSolo.contains(all)) {
                    timer --;
                    sec --;
                }
                if (Arrays.inSologameSolo.size() == 0) {
                    timer = 900;
                    sec = 60;
                    cancel();
                }
                if (sec == 0) {
                    sec = 60;
                }
                if ((timer == 0) && (sec == 0)) {
                    for (Player dd : Bukkit.getOnlinePlayers()) {
                        if (Arrays.inSologameSolo.contains(dd)) {
                            Arrays.inSologameSolo.remove(dd);
                            Arrays.inWAITLOBBYsolo.remove(dd);
                            Arrays.inLOBBY.add(dd);
                            String w = Lobbyies.getconfig().getString("Flobby.name");
                            double x = Lobbyies.getconfig().getDouble("Flobby.x");
                            double y = Lobbyies.getconfig().getDouble("Flobby.y");
                            double z = Lobbyies.getconfig().getDouble("Flobby.z");
                            float yaw = (float) Lobbyies.getconfig().getDouble("Flobby.yaw");
                            float pitch = (float) Lobbyies.getconfig().getDouble("Flobby.pitch");
                            Location a = new Location(Bukkit.getWorld(w), x, y, z, yaw, pitch);
                            dd.teleport(a);
                            dd.getInventory().clear();
                        }
                    }
                    timer = 900;
                    sec = 60;
                    cancel();
                }
            }
        }
     
    #1 bmwdev, Nov 4, 2018
    Last edited: Nov 4, 2018
  2. Can you use code tags so its easier to read? [code ][/ code]
     
  3. And add indentation so we can read it
     
  4. Can you explain what are you trying to reach and what's not working?
     
  5. thi code not work why timer and sec no down

    Code (Java):
        public void run() {
            for (Player all : Bukkit.getOnlinePlayers()) {
                if (Arrays.inSologameSolo.contains(all)) {
                    timer --;
                    sec --;
                }
     
  6. I can only assume your collection is empty. Try debugging it's size and see if it's not. You should also add some debugging in your if statements to see whether they are being run or not.
     
    • Like Like x 1
  7. Why do I get the feeling like this is the same problem you had before? :unsure: Reference

    Again, why are you looping through every player in that runnable? It's fine if it's not constantly running, but if that runnable is running on a timer, then the for loop is unnecessary. You just need to check to see if your collection contains the player.
     
  8. If this is solved, please don't advertise your plugins again :rolleyes::rolleyes::rolleyes:
    upload_2018-11-4_7-57-27.png
     
    • Funny Funny x 3
  9. Ahahahahahahaha

    What are you even doing there again. Thats the same error as you had last time round. You are decrementing for every player on the server again? You are decrementing your minutes every time you are running this? What??

    Stop using ticks to measure time!

    Code (Java):
    long startedAt = System.currentTimeMillis();
    long maximumUpTime = 1000L * 60*15; // 15 minutes

    [...]

    @Override
    public void run() {
      if (System.currentTimeMillis() - startedAt > maximumUptime) {
        // code is run when 15 minutes passed.
      }
    }
     
  10. I ain't happy, i'm feeling glad
    I have some bag in my code
    ... no wait