Skip to content

Commit

Permalink
Make protectionTimer publicly accessible (#102)
Browse files Browse the repository at this point in the history
* Update ProtectionTime.java

Changed some stuff to public for API usage

* Update ProtectionTime.java

Should compile now, also made the code simpler in getCountdownMin and getCountdownSec

* Update ProtectionTime.java

* Update ProtectionTime.java

* Update ProtectionTime.java

* Update ProtectionTime.java

* Update ProtectionTime.java

* Update ProtectionTime.java

* Update src/main/java/de/cuuky/varo/game/start/ProtectionTime.java

Using Integer might be better

Co-authored-by: Almighty-Satan <[email protected]>

* Update src/main/java/de/cuuky/varo/game/start/ProtectionTime.java

Co-authored-by: Almighty-Satan <[email protected]>

* Update ProtectionTime.java

* Clean up MR

---------

Co-authored-by: Almighty-Satan <[email protected]>
  • Loading branch information
Kalibrier and Almighty-Satan authored Jan 11, 2025
1 parent 69369c2 commit 6388414
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 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,44 +21,53 @@ public ProtectionTime(int timer) {
}

private void startGeneralTimer(int timer) {
if (timer == 0) {
throw new IllegalArgumentException();
}

this.protectionTimer = timer;
this.scheduler = new BukkitRunnable() {

private int protectionTimer = timer;

@Override
public void run() {
if (!Main.getVaroGame().isRunning()) {
scheduler.cancel();
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 != timer
&& ProtectionTime.this.protectionTimer % ConfigSetting.STARTPERIOD_PROTECTIONTIME_BROADCAST_INTERVAL.getValueAsInt() == 0) {
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);
}

/**
* Returns the protection timer
*
* @return the protection timer
*/
public int getProtectionTimer() {
return this.protectionTimer;

if (sec < 10)
return "0" + sec;
else
return sec + "";
}
}
}

0 comments on commit 6388414

Please sign in to comment.