Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make protectionTimer publicly accessible #102

Merged
merged 12 commits into from
Jan 11, 2025
45 changes: 27 additions & 18 deletions src/main/java/de/cuuky/varo/game/start/ProtectionTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class ProtectionTime {

private BukkitTask scheduler;
private int protectionTimer;

public ProtectionTime() {
startGeneralTimer(ConfigSetting.STARTPERIOD_PROTECTIONTIME.getValueAsInt());
Expand All @@ -20,9 +21,14 @@ public ProtectionTime(int timer) {
}

private void startGeneralTimer(int timer) {
this.scheduler = new BukkitRunnable() {
this.protectionTimer = timer;

private int protectionTimer = timer;
if (this.protectionTimer == 0) {
Main.getVaroGame().setProtection(null);
return;
}
Kalibrier marked this conversation as resolved.
Show resolved Hide resolved

this.scheduler = new BukkitRunnable() {

@Override
public void run() {
Expand All @@ -31,33 +37,36 @@ public void run() {
return;
}

if (this.protectionTimer == 0) {
if (ProtectionTime.this.protectionTimer == 0) {
Main.getLanguageManager().broadcastMessage(ConfigMessages.PROTECTION_TIME_OVER);
Main.getVaroGame().setProtection(null);
scheduler.cancel();
} else if (protectionTimer % ConfigSetting.STARTPERIOD_PROTECTIONTIME_BROADCAST_INTERVAL.getValueAsInt() == 0 && this.protectionTimer != timer)
Main.getLanguageManager().broadcastMessage(ConfigMessages.PROTECTION_TIME_UPDATE).replace("%minutes%", getCountdownMin(protectionTimer)).replace("%seconds%", getCountdownSec(protectionTimer));
} else if (ProtectionTime.this.protectionTimer % ConfigSetting.STARTPERIOD_PROTECTIONTIME_BROADCAST_INTERVAL.getValueAsInt() == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to this.protectionTimer != timer?

Main.getLanguageManager().broadcastMessage(ConfigMessages.PROTECTION_TIME_UPDATE)
.replace("%minutes%", getCountdownMin(ProtectionTime.this.protectionTimer))
.replace("%seconds%", getCountdownSec(ProtectionTime.this.protectionTimer));
}

this.protectionTimer--;
ProtectionTime.this.protectionTimer--;
}
}.runTaskTimer(Main.getInstance(), 1L, 20L);
}

private String getCountdownMin(int sec) {
public String getCountdownMin(int sec) {
int min = sec / 60;

if (min < 10)
return "0" + min;
else
return min + "";
return (min < 10) ? "0" + min : String.valueOf(min);
}

private String getCountdownSec(int sec) {
public String getCountdownSec(int sec) {
sec = sec % 60;
return (sec < 10) ? "0" + sec : String.valueOf(sec);
}

if (sec < 10)
return "0" + sec;
else
return sec + "";
/**
*
* @return the protection timer or null if no protection time is set
*/
public int getProtectionTimer() {
return this.protectionTimer > 0 ? protectionTimer : null;
Kalibrier marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Loading