Skip to content

Commit

Permalink
Small code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Flo56958 committed Feb 20, 2024
1 parent d28799b commit e6296a6
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,23 @@ public class ActionBarListener implements Listener {
private static final Runnable run = new Runnable() {
@Override
public void run() {
for (Player p : Bukkit.getOnlinePlayers()) {
Bukkit.getOnlinePlayers().forEach(p -> {
final int xpamount = xpbuffer.get(p.getUniqueId()).getAndSet(0);
if (xpamount != 0) {
String a = String.valueOf(xpamount);
if (xpamount > 0) a = "+" + a;
else continue;
if (xpamount > 0)
ChatWriter.sendActionBar(p, LanguageManager.getString("ActionBar.ExpGain", p)
.replaceAll("%amount", a));
}
}
.replaceAll("%amount", "+" + xpamount));
});
Bukkit.getScheduler().runTaskLater(MineTinker.getPlugin(), this, 20);
}
};


public ActionBarListener() {
for (Player p : Bukkit.getOnlinePlayers()) {
xpbuffer.put(p.getUniqueId(), new AtomicInteger(0));
}
Bukkit.getOnlinePlayers().forEach(p -> xpbuffer.put(p.getUniqueId(), new AtomicInteger(0)));
run.run();
}

public static void addXP(Player p, int amount) {
if (p == null) return;
public static void addXP(@NotNull Player p, int amount) {
final AtomicInteger i = xpbuffer.get(p.getUniqueId());
if (i != null) {
i.addAndGet(amount);
Expand Down
Loading

0 comments on commit e6296a6

Please sign in to comment.