Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit

Permalink
🥡 fix removing instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Belikhun committed May 22, 2022
1 parent 55876c2 commit a925bd1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

import com.github.belikhun.Countdown.CountInstance;
import com.github.belikhun.Countdown.Countdown;
Expand Down Expand Up @@ -30,7 +31,10 @@ public void start(int seconds) {

@Override
public void begin(BossBar bar) {
String message = String.format("&rSự kiện &a%s&r sẽ bắt đầu sau &r%s nữa!",
title, CountInstance.readableTime(seconds));

Bukkit.broadcastMessage(Countdown.colorize(message));
}

@Override
Expand All @@ -43,6 +47,9 @@ public void update(BossBar bar, double remain) {
public void complete(BossBar bar) {
String message = String.format("&r&7#%d &a%s&r đã bắt đầu!", id, title);
bar.setTitle(Countdown.colorize(message));
Bukkit.broadcastMessage(Countdown.colorize("Sự kiện " + message));

removeInstance();
}
});
}
Expand All @@ -51,6 +58,12 @@ public void stop() {
count.stop(String.format("Đã hủy bỏ &d%s", title));
Bukkit.broadcastMessage(Countdown.colorize(
String.format("Sự kiện &7(#%d) &d%s &fđã bị hủy!", id, title)));

removeInstance();
}

public void removeInstance() {
instances.remove(this);
}
}

Expand Down Expand Up @@ -128,7 +141,13 @@ public void countdown(String title, int seconds) {
}

public static void stopAll() {
for (Instance instance : instances)
// Use iterator to avoid ConcurrentModificationException
Iterator<Instance> iterator = instances.iterator();

while (iterator.hasNext()) {
Instance instance = iterator.next();
iterator.remove();
instance.stop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

String message = null;
int length = Integer.parseInt(args[0]);
int length = Countdown.parseTime(args[0]);

if (args.length >= 2)
message = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), ' ');
Expand All @@ -71,8 +71,8 @@ public void start(String reason, int seconds) {
@Override
public void begin(BossBar bar) {
String message = (reason != null)
? String.format("&rMáy chủ sẽ tắt sau &b%ds &rnữa! &7(lí do: %s)", seconds, reason)
: String.format("&rMáy chủ sẽ tắt sau &b%ds &rnữa!", seconds);
? String.format("&rMáy chủ sẽ tắt sau &b%s&r nữa! &7(lí do: %s)", CountInstance.readableTime(seconds), reason)
: String.format("&rMáy chủ sẽ tắt sau &b%s&r nữa!", CountInstance.readableTime(seconds));

Bukkit.broadcastMessage(Countdown.colorize(message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public void run() {
public static String readableTime(double seconds) {
return (seconds / 3600d > 1)
? String.format("%s%.1fh&r", timeColor[0], (seconds / 3600d))
: ((seconds > 120d)
? String.format("%s%.1fm&r", timeColor[1], (seconds / 60d))
: ((seconds > 300d)
? String.format("%s%.2fm&r", timeColor[1], (seconds / 60d))
: String.format("%s%.3fs&r", timeColor[2], seconds));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.io.InputStream;
import java.util.logging.Logger;

import javax.annotation.Nullable;

import com.github.belikhun.Countdown.Commands.CountdownCommand;
import com.github.belikhun.Countdown.Commands.ShutdownCommand;
import com.mojang.brigadier.tree.LiteralCommandNode;
Expand Down

0 comments on commit a925bd1

Please sign in to comment.